// 素数判断
#include <stdio.h>

int prime(int n) //素数判断
{
    int i;
    for (i = 2; i <= n / 2; i++)
        if (n % i == 0)
            return 0;
    return 1;
}

int fun(int m, int n, int a[])
{
    int i, j = 0, bw, sw, gw;
    for (i = n; i >= m; i--)
    {
        bw = i / 100 % 10; //取百位数字
        sw = i / 10 % 10;  //取十位数字
        gw = i % 10;       //取个位数字
        if (prime(i) && ((sw + gw) % 10 == bw))
            a[j++] = i;
    }
    return j;
}

void main()
{
    int a[100], m, n;
    int i, k;

    FILE *fp;
    fp = fopen("myf2.txt", "w");

    printf("请输入m和n的值：");
    scanf("%d%d", &m, &n);

    k = fun(m, n, a);
    for (i = 0; i < k; i++)
    {
        if (i % 5 == 0)
        {
            printf("\n");
            fprintf(fp, "\n");
        }
        printf("%6d", a[i]);
        fprintf(fp, "%6d", a[i]);
    }
    fprintf(fp, "\nMy exam number is: 208140133");
    fclose(fp);
}
